/*
 * @Author: szx
 * @Date: 2022-06-13 15:06:56
 * @LastEditTime: 2022-06-13 15:10:18
 * @Description:
 * @FilePath: \leetcode\500-599\560\560.js
 */
/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var subarraySum = function (nums, k) {
    let sum = 0,
        res = 0;
    const map = new Map();
    map.set(0, 0);
    for (let num of nums) {
        sum += num;

        if (map.has(sum - k)) res += map.get(sum - k);
        map.set(sum - k, (map.get(sum - k) || 0) + 1);
    }
    return res;
};
